package com.bw.demo.home

import androidx.lifecycle.MutableLiveData
import com.bw.demo.base.BaseRepo
import com.bw.demo.entity.BaseTypeRepo
import com.bw.demo.entity.BaseVideoRepo
import com.bw.demo.entity.TypeEntity
import com.bw.demo.entity.VideoEntity
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

class HomeRepo : BaseRepo(){
    fun getType(videotype:Int,getSimpleType:Int,success: MutableLiveData<BaseTypeRepo<List<TypeEntity>>>,failure: MutableLiveData<String>){
        getApi().getType(videotype, getSimpleType)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<BaseTypeRepo<List<TypeEntity>>>{
                override fun onSubscribe(d: Disposable) {

                }



                override fun onError(e: Throwable) {
                    failure.value=e.message
                }

                override fun onComplete() {

                }
                override fun onNext(t: BaseTypeRepo<List<TypeEntity>>) {
                    success.value=t
                }

            })
    }
    fun getVideo(channelId: String,page: Int,pagesize: Int,success:MutableLiveData<BaseVideoRepo<List<VideoEntity>>>,failure:MutableLiveData<String>){
        getApi().getVideo(channelId, page, pagesize)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<BaseVideoRepo<List<VideoEntity>>>{
                override fun onSubscribe(d: Disposable) {

                }

                override fun onError(e: Throwable) {
                    failure.value=e.message
                }

                override fun onComplete() {

                }

                override fun onNext(t: BaseVideoRepo<List<VideoEntity>>) {
                   success.value=t
                }

            })

    }
}